package com.hncj.yqfk.utils;

import org.springframework.http.HttpStatus;
import java.util.Date;

class Message<T> {
    Integer code;
    //向前端返回的内容
    Date time;
    //    返回错误
    String errormessage;
    T data;
    public Message() {
    }
    public Message(Integer code, Date time,String errormessage) {
        this.code = code;
        this.time = time;
        this.errormessage = errormessage;
    }
    public Message(Integer code, Date time,String errormessage, T data) {
        this.data = data;
        this.errormessage = errormessage;
        this.code = code;
        this.time = time;
    }
    public static <T> Message<T> custom(Integer code,String errormessage,Date time, T data) {
        return new Message(code,time,errormessage, data);
    }
    public static <T> Message<T> custom(Integer code,String errormessage, Date time) {
        return new Message(code,time,errormessage);
    }
    public static HttpStatus num2HttpStatus(Integer code) {
        HttpStatus status = HttpStatus.NOT_FOUND;
        for (HttpStatus httpStatus : HttpStatus.values()) {
            boolean b = code == httpStatus.value();
            if (b) {
                return httpStatus;
            }
        }
        return status;
    }
    public Integer getCode() {
        return code;
    }
    public void setCode(Integer code) {
        this.code = code;
    }
    public Date getTime() {
        return time;
    }
    public void setTime(Date time) {
        this.time = time;
    }
    public T getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }
    public String getErrormessage() {
        return errormessage;
    }
    public void setErrormessage(String errormessage) {
        this.errormessage = errormessage;
    }
}
